package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import org.omg.PortableServer.LIFESPAN_POLICY_ID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.jws.soap.SOAPBinding;
import javax.sound.midi.Soundbank;
import java.util.List;

@RestController//(@Controller：+@ResponseBody：将服务器端的数据转换为JSON串返回)
@CrossOrigin//开启跨域机制
public class UserController {

    @Autowired
    //编码规则：面向接口编程 （优势：解耦）
    private UserService userService;

    @RequestMapping("/findAll")
    public List<User> findAll(){
        return userService.findALl();
    }

    @GetMapping("findUserById")
    public User findUserById(Integer id){
        return userService.findUserById(id);
    }
    //url:http://localhost:8090/findUserByNS?name=王昭君&sex=女
    @GetMapping("findUserByNS")
    public List<User> findUserByNS(User user){

        return  userService.findUserByNS(user);
    }

    //使用RESTful
/*    @GetMapping("/user/{name}/{age}")
    public List<User> findUserByNA(@PathVariable String name,
                                   @PathVariable Integer age){
        System.out.println(name);
        System.out.println(age);
        return null;
    }*/

    @GetMapping("/user/{name}/{age}")
    public List<User> findUserByNA2(User user){
        return userService.findUserByNA2(user);
    }

    //url:http://localhost:8090/getUserByIds/ids=1,3,4,5
    @GetMapping("getUserByIds")
    public List<User> getUserByIds(Integer[] ids){

        return userService.getUserByIds(ids);
    }


}
